package com.woniuxy01;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author 作者
 * @create 2025-08-01 14:31
 */
public class Test06 {
    public static void main(String[] args) throws IOException {
    }

    private static void test06() throws IOException {
        FileReader fr=new FileReader("d:\\aaa\\a.png");
        FileWriter fw=new FileWriter("d:\\aaa\\b.png");
        char[] chars=new char[1024];
        int lenght=0;
        while((lenght=fr.read(chars))!=-1){
            fw.write(chars,0,lenght);
            fw.flush();
        }
        fw.close();
    }

    private static void test05() throws IOException {
        FileWriter fw=new FileWriter("a.txt");
        fw.write("aaaa中文");
        fw.flush();
        fw.close();

        FileReader fr=new FileReader("a.txt");
        int mychar=0;
        while((mychar=fr.read())!=-1){
            System.out.println((char) mychar);
        }
        fr.close();
    }

    private static void test04() throws IOException {
        OutputStreamWriter osw =
                new OutputStreamWriter(new FileOutputStream("a.txt"),"gbk");
        osw.write("abcdrg中文字wrereeee符");
        osw.flush();
        osw.close();


        InputStreamReader isr =new InputStreamReader(new FileInputStream("a.txt"),"gbk");
        int length=0;
        char[] chars = new char[2];
        while((length=isr.read(chars))!=-1){
            System.out.println(new String(chars,0,length));
        }
    }

    private static void test03() throws IOException {
        InputStreamReader isr =
                new InputStreamReader(new FileInputStream("a.txt"));
        int mychar=0;
        while((mychar=isr.read())!=-1){
            //一次读取一个字符
            System.out.println((char)mychar);
        }
    }

    private static void test02() throws IOException {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("a.txt"));
        //一次写一个字符
        osw.write(97);
        osw.write("中");
        osw.write("abcdrg中文字wrereeee符");
        //字符流写入数据以后，刷新缓存区,循环写入，每次循环结束刷新一次
        osw.flush();
        osw.close();
    }

    private static void test01() throws UnsupportedEncodingException {
        //IDE使用UTF-8
        String str="abc中文";
        //编码
        byte[] bytes = str.getBytes("utf-8");
        System.out.println(Arrays.toString(bytes));
        //解码
        System.out.println(new String(bytes, "gbk"));
    }


}
